//
//  BYProductListCell.m
//  OCDemo
//
//  Created by zhumuzhi on 2022/2/14.
//

#import "BYProductListCell.h"
#import "ProductModel.h"

@interface BYProductListCell ()

@property (nonatomic, strong) UIImageView   *icon;
@property (nonatomic, strong) UILabel       *title;
@property (nonatomic, strong) UILabel       *price;

@end

@implementation BYProductListCell

#pragma mark - CellHeight

+ (CGFloat)CellHeight {
    return kAutoWithSize(160);
}

#pragma mark - SetData

- (void)setModel:(ProductModel *)model {
    _model = model;
    
    self.icon.image = [UIImage imageNamed:model.product_iconimage];
    self.title.text = model.product_name;
    self.price.attributedText = [NSMutableAttributedString productPriceText:model.product_price marketPrice:model.product_marketprice];
}

#pragma mark - Init

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        UIImageView *icon = [[UIImageView alloc] init];
        [self.contentView addSubview:icon];
        self.icon = icon;
        
        UILabel *title = [[UILabel alloc] init];
        title.font = MZFont(15);
        title.numberOfLines = 2;
        [self.contentView addSubview:title];
        self.title = title;
        
        UILabel *price = [[UILabel alloc] init];
        [self.contentView addSubview:price];
        self.price = price;
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(kAutoWithSize(140), kAutoWithSize(140)));
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(self.mas_left).offset(kAutoWithSize(10));
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.icon).offset(kAutoWithSize(10));
        make.left.equalTo(self.icon.mas_right).offset(kAutoWithSize(5));
        make.right.equalTo(self.contentView).offset(-kAutoWithSize(10));
    }];
    
    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.title);
        make.bottom.equalTo(self.icon.mas_bottom);
    }];
    
    [super layoutSubviews];
}

@end
